package com.platform.user.center.portal.controller;

import com.github.pagehelper.PageInfo;
import com.platform.user.center.portal.entity.AlipayUser;
import com.platform.user.center.portal.entity.VirtualTransitCard;
import com.platform.user.center.portal.service.AlipayUserService;
import com.platform.user.center.portal.util.BaseResponse;
import com.platform.user.center.portal.util.PageUtils;
import com.platform.user.center.portal.util.ResultCodeAndMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by churcy on 2017/6/9.
 */
@RestController
public class AlipayUserController {
    @Autowired
    private AlipayUserService alipayUserService;

    @GetMapping(value = "/user/list")
    public Object userList(HttpServletRequest request) {
        Map<String, Object> response = new HashMap<>();
        Map<String, Object> result = new HashMap<>();
        try {
            do {
                String userId = request.getParameter("userId");
                String createTime = request.getParameter("createTime");
                String pageSize = request.getParameter("pageSize");
                String pageNum = request.getParameter("pageNum");

                Map<String, Object> conditions = new HashMap<>();

                conditions.put("userId", userId);
                conditions.put("createTime", createTime);
                conditions.put("pageSize", pageSize != null ? pageSize : "10");
                conditions.put("pageNum", pageNum != null ? pageNum : "1");
                List<AlipayUser> alipayUserList = alipayUserService.findByConditions(conditions);

                result.put("alipayUserList", alipayUserList);
                result.put("page", PageUtils.formatPage(new PageInfo(alipayUserList)));

                response = BaseResponse.setResponse(result, ResultCodeAndMessage.SUCCESS);
            } while (false);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return response;
    }


}
